package dao.impl;

import dao.UserDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.dept;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class UserDaoImpl implements UserDao {
    @Override
    public List<dept> findAll() {
        //引入mybatis—config.xml配置文件
        String resource = "mybatis-config.xml";
        SqlSession sqlSession = null;
        try{
        InputStream resourceAsStream = Resources.getResourceAsStream(resource);
        //创建绘画工厂对像
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //获取绘画对象
        sqlSession = sqlSessionFactory.openSession();
        //执行查询
        List<dept> users = sqlSession.getMapper(UserDao.class).findAll();
        return users;
        }  catch (IOException e) {
            throw new RuntimeException(e);

        } finally {
            sqlSession.close();
        }



    }
}
